import * as servicesApi from '@/services/template'

export default {
    spacename: 'template',
    state: {
        list: []
    },
    effects: {
        // list
        *selectAllShop({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.selectAllShop, payload) 
            if (res.httpStatus === 200) {
                return res
            }
        },
        *updateProductTemplate({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.updateProductTemplate, payload) 
            console.log(res, 'rrrrr');
            
            if (res.httpStatus === 200) {
                return res
            }
        },
        *updateProductBindShopId({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.updateProductBindShopId, payload) 
            console.log(res, 'rrrrr');
            
            if (res.httpStatus === 200) {
                return res
            }
        },
        *auditProductTemplate({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.auditProductTemplate, payload) 
            console.log(res, 'rrrrr');
            
            if (res.httpStatus === 200) {
                return res
            }
        },
        *selectShopRuleAndGiveBackByShopId({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.selectShopRuleAndGiveBackByShopId, payload)  
            if (res.httpStatus === 200) {
                return res.data
            }
        },
        *selectDistrict({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.selectDistrict, payload)  
            if (res.httpStatus === 200) {
                return res.data
            }
        },
        *insertProductTemplateAddress({ payload, callback }, { put, call }) {
            const res = yield call(servicesApi.insertProductTemplateAddress, payload)  
            if (res.httpStatus === 200) {
                return res.data
            }
        },
        // *selectBusinessPrdouctTemplate({ payload, callback }, { put, call }) {
        //     const res = yield call(servicesApi.selectBusinessPrdouctTemplate, payload) 
        //     console.log(res, 'rrrrr');
            
        //     if (res.httpStatus === 200) {
        //         return res
        //     }
        // },

    },
    reducers: {
        saveList(state, { payload }) {
            console.log()
            // let _state = JSON.parse(JSON.stringify(state));
            // _state.list = (payload.data && payload.data.records) || [];
            // return _state;
            return {
                ...state,
                list: payload.data.records
            }
        }
    }
}
